package com.baijia.authentication.principal.credentials;

import com.baijia.authentication.handler.support.encoder.PasswordEncoder;
import com.baijia.authentication.handler.support.encoder.PlainTextPasswordEncoder;
import com.baijia.authentication.principal.Credentials;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * Created by dudu on 16/4/26.
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class PassportCredentials extends Credentials {

    private static final long serialVersionUID = 3634754468428582059L;

    private String username;
    private String password;
    private boolean isSms;
    private String countryCode;
    private Integer accountType;

    private transient PasswordEncoder encoder;

    public PassportCredentials(String username, String password, String userRole, String countryCode, boolean isSms,
        boolean rememberMe, int accountType) {
        this(username, password, userRole, countryCode, isSms, rememberMe, accountType, new PlainTextPasswordEncoder());
    }

    public PassportCredentials(String username, String password, String userRole, String countryCode, boolean isSms,
        boolean rememberMe, int accountType, PasswordEncoder encoder) {
        this.encoder = encoder;
        this.username = username;
        this.password = this.encoder.encode(password);
        this.countryCode = countryCode;
        this.isSms = isSms;
        this.accountType = accountType;
        setRememberMe(rememberMe);
        setUserRole(Integer.parseInt(userRole));
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public String toString() {
        return "{username: " + username + ", password: ***}";
    }

}